package com.vectrics.hosting;

import org.apache.log4j.Logger;
import org.vectrics.common.util.FileCopy;
import org.vectrics.domain.Domain;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.user.Person;
import org.vectrics.user.UserPrivilegeType;

public class ChangeThemeHelper {
    private Logger log = Logger.getLogger(this.getClass());

    public void execute(Person authPerson, Domain domain, String themeName) {
        UserPrivilegeType htmlChangePriv = CoreServiceLocator.getPersonService().findUserPrivilegeType("html.change");

        String targetDir = CoreServiceLocator.getConfiguration().getHtmlStyleDirectory();
        if (targetDir.endsWith("/") == false) {
            targetDir += "/";
        }
        targetDir += domain.getId().toString();
        targetDir += "/public.standard";

        String themesSrcDirectory = CoreServiceLocator.getConfiguration().getDataDirectory() + "/theme-src-files" + "/"
                + themeName;

        log.info("Copying theme directory: " + themesSrcDirectory + "  Target: " + targetDir);
        FileCopy.copyDirectory(themesSrcDirectory, targetDir);
    }

}
